import Mock from 'mockjs'

const data = Mock.mock({
  'items|30': [{
    id: '@id',
    content: '<p>' + '@sentence(10, 20)' + '</p>',
    'status|1': ['published', 'draft', 'deleted'],
    title: 'name',
    release_time: '@datetime',
    pageviews: '@integer(300, 5000)'
  }]
})

export default [
  {
    url: 'api/v1/article/',
    type: 'get',
    response: config => {
      const articleId = config.url.split('/').reverse()[1]

      const items = data.items
      if (articleId.length > 10) {
        const datas = items.filter((i) => {
          return i.id == articleId
        })
        return {
          ...datas[0]
        }
      }
      return {
        code: 20000,
        count: items.length,
        results: items
      }
    }
  },
  {
    url: 'api/v1/article/',
    type: 'put',
    response: config => {
      const articleId = config.url.split('/').reverse()[1]

      const items = data.items
      if (articleId.length > 10) {
        const datas = items.filter((i) => {
          return i.id == articleId
        })
        return {
          ...datas[0]
        }
      }
      return {
        code: 20000,
        count: items.length,
        results: items
      }
    }
  }
]
